package com.tedu.springmvc.controller;

import com.tedu.springmvc.mapper.UserInfoMapper;
import com.tedu.springmvc.pojo.dto.UserDTO;
import com.tedu.springmvc.pojo.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    @Autowired
    private UserInfoMapper userInfoMapper;
//    @RequestMapping("/regUser")
//    @ResponseBody
//    public String reg(HttpServletRequest request){
//        System.out.println("开始处理用户操作");
//        String username = request.getParameter("username");
//        String password = request.getParameter("password");
//        String nickname = request.getParameter("nickname");
//        String age = request.getParameter("age");
//        System.out.println(username+","+password+","+nickname+","+age);
//        return "注册成功";
//    }



//    @RequestMapping("/regUser")
//    @ResponseBody
//    public String reg(String username,String password,String nickname,int age){
//        System.out.println(username+","+password+","+nickname+","+age);
//        return "注册成功,你赖东东不错嘛~";
//    }
    @RequestMapping("/regUser")
    @ResponseBody
    public String reg(UserDTO userDTO){
        System.out.println(userDTO);
        UserInfo userInfo=new UserInfo();
        userInfo.setUsername(userDTO.getUsername());
        userInfo.setPassword(userDTO.getPassword());
        userInfo.setNickname(userDTO.getNickname());
        userInfo.setAge(userDTO.getAge());
        int num = userInfoMapper.insertUserInfo(userInfo);
        System.out.println(num>0?"注册成功":"注册失败");
        return "注册成功 BOOMKAKA BOOMKAKA";
    }
}
